package mm.apk.libmm.ui.activity

import android.content.Intent
import android.os.Bundle
import mm.apk.libmm.presenter.BasePresenter

/**
 * Descriptions：
 * StartVersion：
 * <p>
 * Author：ChenME
 * Date：2019-11-15
 * Email：ibelieve1210@163.com
 */
abstract class PresenterActivity<P : BasePresenter<*>> : BaseActivity()  {

    protected val mPresenter: P by lazy { presenter() }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        view()
        addLifecycleObserver(mPresenter)
        onCreate()
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        mPresenter.onActivityResult(requestCode, resultCode, data)
    }

    protected abstract fun onCreate()

    /**
     * 子类返回
     * return XXXPresenter()
     */
    protected abstract fun presenter(): P

    /**
     * 子类调用
     * mPresenter.loadView(this)
     */
    protected abstract fun view()
}